Let’s investigate some of the per game statistics of NBA teams during the 2020 season!

Team of interest: Golden State Warriors

br_url <- paste0("https://www.basketball-reference.com/leagues/NBA_",params$season,".html")

## Get NBA per game data
df <- read_html(br_url) %>% 
  html_table(fill = T) %>%
  .[[6]] %>%
  tibble() %>%
  select(-Rk) %>%
  janitor::clean_names() %>%
  filter(team != "League Average") %>% 
  mutate(
    team_of_interest = grepl(params$team,team,fixed = TRUE)
  )

Off/Def Rebounds XY Plot

df %>%
  ggplot(aes(x = orb, y = drb)) +
  geom_point(aes(
    color = team_of_interest
    ),
    size = 3) +
  geom_vline(aes(xintercept = mean(orb)),
             linetype = "dashed",
             size = 1.2) +
  geom_hline(aes(yintercept = mean(drb)),
             linetype = "dashed",
             size = 1.2) +
  ggrepel::geom_text_repel(aes(label = team)) +
  scale_color_manual(
    values = c("black","green")
  ) + 
  theme(
    legend.position = "none"
  )
Offensive and Defensive Rebounds for each Team

Offensive and Defensive Rebounds for each Team

Team 3-Point Scoring

three_pt <- df %>%
  mutate(
    three_z = z_score(x3p_percent),
    three_pt_pct = scales::percent(x3p_percent, accuracy = 0.1)
    ) %>%
  ggplot(
    aes(
      x = three_z,
      y = reorder(team, three_z),
      label = three_pt_pct
      )
    ) +
  geom_col(width = 0.2) +
  geom_point(
    aes(
      color = team_of_interest,
      size = x3pa
      )) +
  geom_vline(
    xintercept = 0,
    size = 1.2) +
  scale_x_continuous(
    breaks = seq(-3, 3, 1),
    labels = seq(20, 80, 10)
    ) +
  scale_color_manual(
    name = "Team of Interest",
    values = c("black","green")
  ) + 
  theme(
    legend.position = "none"
    ) +
  labs(
    x = "Three Point% t-score",
    y = NULL,
    title = paste(params$season,"Three Point%"),
    subtitle = "Dot Size = 3 Point Attempts"
    )

ggplotly(three_pt)